using System;

namespace complex.Domain
{
    public class Address : IEquatable<Address>
    {
        public virtual string Line1 { get; set; }
        public virtual string City { get; set; }
        public virtual string State { get; set; }
        public virtual string ZipCode { get; set; }

        public override string ToString()
        {
            return string.Format(@"{0}
{1}, {2} {3}", Line1, City, State, ZipCode);
        }

        public virtual bool Equals(Address other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;
            return Equals(other.Line1, Line1)
                   && Equals(other.City, City)
                   && Equals(other.State, State)
                   && Equals(other.ZipCode, ZipCode);
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            if (obj.GetType() != typeof (Address)) return false;
            return Equals((Address) obj);
        }

        public override int GetHashCode()
        {
            unchecked
            {
                var result = (Line1 != null ? Line1.GetHashCode() : 0);
                result = (result*397) ^ (City != null ? City.GetHashCode() : 0);
                result = (result*397) ^ (State != null ? State.GetHashCode() : 0);
                result = (result*397) ^ (ZipCode != null ? ZipCode.GetHashCode() : 0);
                return result;
            }
        }

        public static bool operator ==(Address left, Address right)
        {
            return Equals(left, right);
        }

        public static bool operator !=(Address left, Address right)
        {
            return !Equals(left, right);
        }
    }
}